package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/17 09:54
 * @description
 */
public class Code17 {
    private List<List<String>> l = Arrays.asList(Arrays.asList("a", "b", "c"), Arrays.asList("d", "e", "f"),
        Arrays.asList("g", "h", "i"), Arrays.asList("j", "k", "l"), Arrays.asList("m", "n", "o"),
        Arrays.asList("p", "q", "r", "s"), Arrays.asList("t", "u", "v"), Arrays.asList("w", "x", "y", "z"));
    private List<String> result = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if (digits == null || digits == "") {
            return result;
        }
        int i = Integer.parseInt(digits.charAt(0) + "");

        if (result.size() != 0) {
            List<String> temp = new ArrayList<>();
            for (String s1 : result) {
                for (String s2 : l.get(i - 2)) {
                    temp.add(s1 + s2);
                }
            }
            result = temp;
        } else {
            result.addAll(l.get(i - 2));
        }
        if (digits.length() > 1) {
            letterCombinations(digits.substring(1));
        }
        return result;
    }
}
